﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FzWeb.Models
{
    /// <summary>
    /// 岗位服务类
    /// </summary>
    public class PostService
    {
        public Entities db
        {
            get
            {
                if (HttpContext.Current.Session["db"] == null)
                {
                    HttpContext.Current.Session["db"] = new Entities();
                }
                return HttpContext.Current.Session["db"] as FzWeb.Models.Entities;
            }
        }


        public IList<Post> GetPostList()
        {
            return db.Post.Include("company").Where(c=>c.Status==1).OrderByDescending(c => c.PostTime).ToList();
        }

        public IList<Post> GetPostListAll()
        {
            return db.Post.Include("company").OrderByDescending(c => c.PostTime).ToList();
        }


        public IList<Post> GetPostList(Func<Post, bool> predict)
        {
            return db.Post.Include("company").Where(predict).OrderByDescending(c => c.PostTime).ToList();
        }

        public Post GetPost(int id)
        {
            return db.Post.Include("company").First(c => c.PostId == id);

        }

        public Post GetPost(Func<Post, bool> predict)
        {
            if (db.Post.Where(predict).Count() > 1)
            {
                return db.Post.Include("company").Where(predict).First();
            }
            else
            {
                return null;
            }
        }

        public void AddPost(Post post)
        {
            db.AddToPost(post);
            db.SaveChanges();
        }

        public void SaveChanges()
        {
            db.SaveChanges();
        }
        //public IList<Post> PostSearch(string vocationId, string postClassId, string workAreaId, 
        // int   postDate, int workLength, string education, string postKeyWord, int searchType, string postType)
        //{
        //    return db.pGetPost(vocationId, postClassId, workAreaId, postDate, workLength, education, postKeyWord, searchType, postType).ToList(); 
        //}
        
    }
}
